<?php
define('DATABASE','dealscombined');
require("/var/www/sandbox/dealscombined.co.uk/scripts/connect.php");

// Select DB
$db=mysql_select_db(DATABASE,$connect);
if(!$db) {
die('Can\'t use DATABASE : '.mysql_error());
}

$file = "categories.json";
$categories = json_decode(file_get_contents($file), true);
$result = mysql_query("SELECT * FROM categories");

$topLevelCategories = array();
while($row = mysql_fetch_assoc($result)){

$topLevelCategories[$row["id"]] = $row["category"];

}

echo'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Dealscombined Mapper</title>
		<meta name="author" content="Adrian">
		<!-- Date: 2013-03-03 -->
	</head>
	<body>
		<div id="mappingContainer">
			<form name="newCategory" action="newMapping.php" method="post">
				<div id="keywords">
					<label>1:</label><input name="keyword1" id="keyword1" type="text">&nbsp;
					<label>2:</label><input name="keyword2" id="keyword2" type="text">&nbsp;
					<label>3:</label><input name="keyword3" id="keyword3" type="text">&nbsp;
					<label>4:</label><input name="keyword4" id="keyword4" type="text">&nbsp;
					<label>5:</label><input name="keyword5" id="keyword5" type="text">
				</div>
				<br/>
				<br/>
				<div id="categoryContainer">
					<table id="categoriesTable" cellpadding="10">
						<thead>
							Categories
						</thead><tr>';
						foreach($categories as $key => $value)
						{
						if ($key%5 == 1)
						{
						echo '</tr>
						<tr>';						
						}
							echo'<td><input type="checkbox" name="category[]" value="'.$key.'">'.$value.'</td>';
						}
							echo'</tr>
					</table>
				</div>
				<input name="submit" id="submit" type="submit">
			</form>
		</div>
	</body>
</html>
';
?>